package com.wsd.smartcarwasher.controller;

import com.wsd.smartcarwasher.constans.ResultState;
import com.wsd.smartcarwasher.domain.UserInfo;
import com.wsd.smartcarwasher.service.SavaScalingService;
import com.wsd.smartcarwasher.service.WxService;
import com.wsd.smartcarwasher.util.ReturnUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "省时省钱省水比例相关")
@CrossOrigin
@RestController
public class SaveScalingController {

    @Resource
    private WxService wxService;
    @Resource
    private SavaScalingService savaScalingService;

    @ApiOperation(
            value = "(新增)小程序-查询当前用户的省时、省钱、省水比例",
            notes = "省时、省钱、省水比例",
            produces = "application/json",
            response = ModelMap.class
    )
    @RequestMapping(
            value = {"v1/save_scaling"},
            method = {RequestMethod.GET},
            produces = {"application/json; charset=utf-8"}
    )
    @ResponseBody
    public ModelMap getSaveScaling(HttpServletRequest request) {
        String sessionId = request.getHeader("authorization");
        UserInfo user = this.wxService.getUserInfoBySessionId(sessionId);
        return user == null ? ReturnUtil.Error(ResultState.GET_USER_INFO_FAILED.getMsg()) : ReturnUtil.Success(ResultState.QUERY_USER_CARD_ORDERS_SUCCESS.getMsg(), this.savaScalingService.outSaveScaling(this.savaScalingService.lookSaveScaling(user.getUserId())));
    }


}
